package com.puppy.controller;


import com.aliyuncs.exceptions.ClientException;
import com.puppy.pojo.Result;
//import com.puppy.utils.AliyunOSSOperator;
import com.puppy.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
//import com.aliyun.oss.AliyunOSSOperator;

import java.io.IOException;
import java.util.Objects;

@Slf4j
@RequestMapping("/upload")
@RestController
public class UploadController {
    //注入AliyunOSSOperator,自己写的starter依赖，引入了starter之后，就可以直接使用starter提供的功能了
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    /*上传阿里云*/
    @PostMapping
    public Result upload(MultipartFile file) throws IOException, ClientException {
        log.info("文件上传；{}",file.getOriginalFilename());
        //将文件交给阿里云进行上传
        String url = aliyunOSSOperator.upload(file.getBytes(), Objects.requireNonNull(file.getOriginalFilename()));
        log.info("文件上传成功，url为：{}",url);
        return Result.success(url);
    }
}
